const express = require('express');
const mongo = require('../dataBase/db');
const router = express.Router();

router.post('/getInfo', async(req, res) => {
    let userId = req.body.userId;
    let result = await mongo.users.findOne({ userId: userId });
    if (result == null) {
        res.send({ status: false, content: "验证失效，请重新登陆" });
    } else {
        let body = {
                avatarImg: result.avatarImg,
                name: result.name,
                coin: result.coin,
                grade: result.grade,
                exp: result.exp,
                fans: result.fans.length,
                subAmount: result.subscribe.length
            }
            // console.log(body);
        res.send({ status: true, body: body, content: "成功获取到用户内容" });
    }
})

router.post('/changeName', (req, res) => {
    let userId = req.body.userId;
    mongo.users.update({ userId: userId }, { name: req.body.name }, (err, row) => {
        if (err) throw err;
        res.send({ status: true, content: "修改成功" });
    })
})

module.exports = router;